<?php

namespace app\admin\dao;

use app\common\model\Role;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * RoleDao 数据访问对象
 * Class RoleDao
 * @package app\admin\dao
 * @method Role findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method Role insertActive(array $params, array $allow_field = [])
 * @method Role updateActive(Role $model, array $params, array $allow_field = [])
 * @method Role findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method Role updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(Role $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class RoleDao
{
    use DaoTrait;

    /**
     * @var Role
     */
    private $baseModel;

    /**
     * RoleDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = Role::class;
    }

    public function listRoles(?int $page, ?int $page_size): array
    {
        $query = Role::where('roleType', Role::ROLE_TYPE_ADMIN)
            ->order('id', 'DESC')
            ->paging($page, $page_size);

        return listOutput($query, $page_size);
    }
}
